/**
 * 审计服务器模块：增、删、改、查
 */
package com.axt.dbaudit.bean.cfg;

import java.util.List;

import com.axt.dbaudit.base.MsgFuncExt;
import com.axt.dbaudit.model.cfg.TargetDB;
import com.axt.soa.bean.BaseFuncBean;
import com.axt.soa.msg.types.MsgErrorCode;
import com.axt.soa.msg.types.MsgParam;

/**
 * @author njg
 * 
 */
public class TargetDBBean extends BaseFuncBean {
	/**
	 * 获取审计服务器列表
	 * 
	 * @return List<TargetDB>
	 */
	public List<TargetDB> getTargetDBList(String serverPath) {
		prepare(serverPath);
		return fetch(MsgFuncExt.FUNC_QUERY_AUDIT_TG_SERVER,
				"com.axt.dbaudit.model.cfg.TargetDB", "au_params", CONN_T_TCP);
	}

	/**
	 * 添加审计服务器
	 * 
	 * @param oTargetDB
	 * @return boolean
	 */
	public int AddTargetDB(String serverPath, TargetDB targetDB) {
		prepare(serverPath);

		request.addParam(MsgParam.MSG_COL_AU_NAME, targetDB.getAu_Name());
		request.addParam(MsgParam.MSG_COL_AU_DBTYPE, targetDB.getAu_DBType());
		request.addParam(MsgParam.MSG_COL_AU_IP, targetDB.getAu_IP());
		request.addParam(MsgParam.MSG_COL_AU_PORT, targetDB.getAu_port());
		request.addParam(MsgParam.MSG_COL_AU_FIREWALL_PORT,
				targetDB.getAu_firewall_port());
		request.addParam(MsgParam.MSG_COL_AU_OTHERPORT,
				targetDB.getAu_Otherport());
		request.addParam(MsgParam.MSG_COL_AU_DELETED, targetDB.getAu_Deleted());
		request.addParam(MsgParam.MSG_COL_AU_ISENABLE,
				targetDB.getAu_isEnable());
		return execute(MsgFuncExt.FUNC_ADD_AUDIT_TG_SERVER, CONN_T_TCP);
	}

	/**
	 * 删除给定Id的审计服务器
	 * 
	 * @param aServerid
	 * @return
	 */
	public int DeleteTargetDB(String serverPath, String serverid) {
		prepare(serverPath);

		request.addParam(MsgParam.MSG_COL_AU_SERVER_ID, serverid);
		return execute(MsgFuncExt.FUNC_DELETE_AUDIT_TG_SERVER, CONN_T_TCP);
	}

	/**
	 * 更新审计服务器
	 * 
	 * @param oTargetDB
	 * @return
	 */
	public int UpdateTargerDB(String serverPath, TargetDB targetDB) {
		prepare(serverPath);

		request.addParam(MsgParam.MSG_COL_AU_NAME, targetDB.getAu_Name());
		request.addParam(MsgParam.MSG_COL_AU_DBTYPE, targetDB.getAu_DBType());
		request.addParam(MsgParam.MSG_COL_AU_IP, targetDB.getAu_IP());
		request.addParam(MsgParam.MSG_COL_AU_PORT, targetDB.getAu_port());
		request.addParam(MsgParam.MSG_COL_AU_FIREWALL_PORT,
				targetDB.getAu_firewall_port());
		request.addParam(MsgParam.MSG_COL_AU_OTHERPORT,
				targetDB.getAu_Otherport());
		request.addParam(MsgParam.MSG_COL_AU_DELETED, targetDB.getAu_Deleted());
		request.addParam(MsgParam.MSG_COL_AU_ISENABLE,
				targetDB.getAu_isEnable());
		request.addParam(MsgParam.MSG_COL_AU_SERVER_ID,
				targetDB.getAu_ServerID());

		return execute(MsgFuncExt.FUNC_UPDATE_AUDIT_TG_SERVER, CONN_T_TCP);
	}
}
